package com.szqhyxj.youxiangju.biz.equipmentActivation.buySlots;

import com.szqhyxj.youxiangju.sys.BaseResult;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by leung on 2018/11/9.
 */

public class BuySlotPresenter implements BuySlotContract.Presenter {
    BuySlotContract.View view;

    public BuySlotPresenter(BuySlotContract.View view) {
        this.view = view;
    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void getOrder(String devno,int nums) {
        BuySlotModel.getSlotpay(devno, "alipayApp",nums)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Consumer<BaseResult<String>>() {
                    @Override
                    public void accept(BaseResult<String> baseResult) throws Exception {
                        if (baseResult.businessLogicSuccess()) {
                            view.navtoApli(baseResult.getData().toString());
                        } else {
                            view.showToast("支付失败！" + baseResult.getMessage());
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        view.showToast("支付失败！" + throwable.getMessage());
                    }
                });
    }
}
